package com.liang.producer;

import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.clients.producer.ProducerRecord;

import java.util.Properties;

public class ProducerWithInterceptor {
    public static void main(String[] args) {
        //1、创建kafka生产信息
        Properties properties = new Properties();
        properties.put("bootstrap.servers","182.92.198.198:9092");//kafka地址

        //kv的序列化类型
        properties.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
        properties.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
        properties.put(ProducerConfig.INTERCEPTOR_CLASSES_CONFIG,"com.liang.interceptor.TimeInterceptor");
        //2、创建生产者对象
        KafkaProducer<String, String> producer = new KafkaProducer<String, String>(properties);
        //3、发送数据

        for (int i = 0; i < 10; i++) {
            producer.send(new ProducerRecord<String, String>("topic01","----"+i));

        }

        //4、关闭
        producer.close();
    }
}

